<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Zenika-Formation Wicket - zenContact</title>
<link id="stylesheet" href="zencontact.css" rel="stylesheet"
	type="text/css" />

<script language="JavaScript" type="text/javascript" src="DatePicker.js"></script>
<script language="JavaScript" type="text/javascript" src="prototype.js"></script>
<script language="JavaScript" type="text/javascript">
function getURLparams(){
	if (window.location.search != "") {
		longueur = window.location.search.length - 1;
		data = window.location.search.substr(1,longueur);
		donnees = data.split("&");
		urlvar = new Array();
		urlvarnum = new Array();
		
		for (var i=0; i < donnees.length; i++) {
				position = donnees[i].indexOf("=");
				variable = donnees[i].substr(0,position);
				pos = position + 1;
				valeur = decodeURI(donnees[i].substr(pos,donnees[i].length));
		
		while (valeur.search(/\+/) != -1)
			valeur = valeur.replace(/\+/," ");
			urlvar[variable] = valeur;
			urlvarnum[i] = valeur;
		}
	} 
	
	return urlvar;
}

function close(){
	window.close();
}

function contact(){
	var urlParams = getURLparams();
	if(parseInt(urlParams["edit"])==1){
		var pid = urlParams["id"];
		var pactive = 0;
		if(document.form.active.checked){
			pactive = 1;
		}
		var pfirstname = document.form.firstName.value;
		var pname = document.form.lastName.value;
		var pemail = document.form.email.value;
		var pcategory = "Professional"; 
		if(document.form.Personal.checked){
			pcategory = "Personal";
		}
		var pbirthdate = document.form.birthDate.value;
		var planguage = document.form.language.value;
		var pnotes = document.form.language.notes;
		new Ajax.Request('editContact.jsp',
			{
				method: 'post', 
				parameters:{
					id: pid,
					active: pactive,
					firstName: pfirstname,
					lastName: pname,
					email: pemail,
					category: pcategory,
					birthDate: pbirthdate,
					language: planguage,
					notes: pnotes	
				}
			}
	
		);
	}else{
		alert("Coucou");
		var pactive = 0;
		if(document.form.active.checked){
			pactive = 1;
		}
		var pcategory = "Professional";
		if(document.form.Personal.checked){
			pcategory = "Personnal";
		}
		var pfirstname = document.form.firstName.value;
		var pname = document.form.lastName.value;
		var pemail = document.form.email.value;
		var pbirthdate = document.form.birthDate.value;
		var planguage = document.form.language.value;
		var pnotes = document.form.notes.value;
		new Ajax.Request('addContact.jsp',
			{
				method: 'post', 
				parameters:{
					active: pactive,
					firstName: pfirstname,
					lastName: pname,
					email: pemail,
					category: pcategory,
					birthDate: pbirthdate,
					language: planguage,
					notes: pnotes	
				}
			}
	
		);
	}
}

var urlParams = getURLparams();
if(parseInt(urlParams["edit"])==1){

new Ajax.Request('contacts.jsp',
		{
			method: 'get', 
			onSuccess: function(transport){
				var contactTags = transport.responseXML.getElementsByTagName("contact");
				var index=0;
				for(var i=0; i<contactTags.length ;i++){
					if(parseInt(contactTags[i].getAttribute("id")) == parseInt(urlParams["id"])){
						index=i;
						alert("Coucou");
					}
				}
					if(parseInt(contactTags[index].getAttribute("active"))==1){
						document.form.active.checked = true;
					}else{
						document.form.active.checked = false;
					}
					if(contactTags[index].getAttribute("category")=="Professional"){
						document.form.Professional.checked = true;
						document.form.Personal.checked = false;
					}else{
						document.form.Professional.checked = false;
						document.form.Personal.checked = true;
					}
					
					document.form.firstName.value = contactTags[index].getAttribute("firstname");
					document.form.lastName.value = contactTags[index].getAttribute("lasstname");
					document.form.email.value = contactTags[index].getAttribute("email");
					document.form.birthDate.value = contactTags[index].getAttribute("birthdate");
					//document.form.language.contactTags[i].getAttribute("language");
					document.form.notes.value = contactTags[index].getAttribute("notes");
			
			}
		}
	
	);
}
</script>
</head>
<body>

<div id="menuPanel">
<panel>
<div id="menu">
	<ul>
		<li><a href="#" id="linkHome"><span id="homeLinkLabel"></span> </a></li>
		<li><a href="#" id="linkAbout"><span id="aboutLinkLabel"></span></a></li>
		<li><select id="localeSelect"></select></li>
	</ul>
</div>
</panel>
</div>

<div id="header">
<h1>zenContact</h1>
<h2>&nbsp;Formation Wicket</h2>
</div>

<div id="content">
<div id="contacts">
<span id="searchPanel">

<panel>
	<form id="searchForm">
	<table cellspacing="3" cellpadding="3">
		<tr>
			<td><message key="label.search">Contact name</message>
			:</td>
			<td><input id="searchString" type="text" name="search" /></td>
			<td><input type="submit" value="Search" class="button"
				id="searchButton"></td>
			<td class="actionLink"><a id="addContact" href="#"><message
				key="label.new">Add new Contact</message></a></td>
		</tr>
	</table>
	</form>
</panel>

</span>
<h2 class="title" id="title">Edit</h2>
<child />
</div>

<div id="contacts">
<div class="contact" align="center">
<span id="feedback"></span>
<form id="form" name="form" action='ViewContactPageFW.html'>
<table cellspacing="5">
	<tr>
		<td><message key="label.active">Active contact</message></td>
		<td><input id="active" type="checkbox" /></td>
	</tr>
	<tr>
		<td><message key="label.firstname">First Name</message></td>
		<td><input id="firstName" type="text" /></td>
	</tr>
	<tr>
		<td><message key="label.name">Last Name</message></td>
		<td><input id="lastName" type="text" /></td>
	</tr>
	<tr>
		<td><message key="label.birthdate">Birthdate</message></td>
		<td>
			<input id="birthDate" type="text" size="10"/>
			<img id="calendar_img" src="images/calendar_icon_1.gif" onClick="GetDate(birthDate);"/>
		</td>
	</tr>
	<tr>
		<td><message key="label.email">Email</message></td>
		<td><input id="email" type="text" size="40" /></td>
	</tr>
	<tr>
		<td><message key="label.category">Category</message></td>
		<td NOWRAP><span id="category">
		<input type="radio" name="Professional"/>Professional <input type="radio" name="Personal"/>Personal
		</span></td>
	</tr>
	<tr>
		<td><message key="label.langues">Language</message></td>
		<td><select id="language" name="language">
			<option value="00">Faites votre choix...</option>
			<option value="Anglais">Anglais</option>
			<option value="Francais">Francais</option>
			<option value="Italien">Italien</option>
			<option value="Allemand">Allemand</option>
			<option value="Espagnol">Espagnol</option>
		</select></td>
	</tr>
	<tr>
		<td valign="top"><message key="label.notes">Notes</message></td>
		<td><textarea id="notes" rows="4" cols="40"></textarea></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td colspan="3" align="center">
			<input id="save" type="submit" value="Save" class="button" onClick="javascript:contact()"/>
			<input id="cancel" type="submit" value="Cancel" class="button" />
		</td>
	</tr>
</table>
</form>
</div>
</div>
</div>

<div id="footer">
<p id="legal"><a href="http://www.zenika.com/">Zenika</a> Copyright
&copy; 2008</p>
</div>

</body>
</html>
